import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import VueCropper from 'vue-cropper'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import tab from './plugins/tab.js' // plugins
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import VCharts from 'v-charts'
import * as echarts from 'echarts'
import '@/styles/ruoyi.scss' // ruoyi css
import '@/utils/dialog' // 引入可拖动的js

import service from '@/utils/request'
import axios from 'axios'
// 引入公用的js
import $ from './utils/js.js'
// 引入公用的样式文件
import './styles/main.css';
// px2rem 自适应
import './utils/lib-flexible/flexible.js'

import '@/styles/index.scss' // global css

import App from './App'
import router from './router'
import store from './store'

import '@/icons' // icon
import '@/permission' // permission control

// import '../static/UEditor/ueditor.config.js'
// import '../static/UEditor/ueditor.all.js'
// import '../static/UEditor/lang/zh-cn/zh-cn.js'
// import '../static/UEditor/ueditor.parse.js'
import VueUeditorWrap from 'vue-ueditor-wrap';
Vue.component('VueUeditorWrap', VueUeditorWrap)

Vue.use(ElementUI, {
	locale
})
Vue.use(VCharts)
Vue.use(VueCropper)

// get请求接口
const getRequest = (url, params = {}) => {
	let paramStr = ''
	for (let key of Object.keys(params)) {
		let name = params[key];
		if (paramStr === '') {
			paramStr += key + '=' + name
		} else {
			paramStr += '&' + key + '=' + name
		}
	}
	return service({
		method: 'get',
		url: `${url}` + '?' + paramStr
	})
}
// post请求接口
const postRequest = (url, params = {}) => {
	return service({
		method: 'post',
		url: `${url}`,
		data: params,
		headers: {
			'Content-Type': 'application/json',

		}
	})
}

// post表单参数接口
const postFormRequest = (url, params) => {
	console.log(params, "params")
	return service({
		method: 'post',
		url: `${url}`, // url的拼接，base就是我们定义的前缀，url就是你传进来的请求
		data: params,
		transformRequest: [function(data) {
			let ret = ''
			for (let it in data) {
				ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
			}
			return ret
		}],
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}
// 文件上传接口
const uploadFileRequest = (url, params) => {
	return service({
		method: 'post',
		url: `${url}`,
		data: params,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}

Vue.config.productionTip = false
Vue.prototype.$service = service
Vue.prototype.$axios = axios
Vue.prototype.$host = process.env.BASE_API
Vue.prototype.$ = $
Vue.prototype.$get = getRequest
Vue.prototype.$post = postRequest
Vue.prototype.$postForm = postFormRequest
Vue.prototype.$uploadFile = uploadFileRequest
Vue.prototype.$echarts = echarts;
Vue.prototype.$tab = tab;

new Vue({
	el: '#app',
	router,
	store,
	template: '<App/>',
	components: {
		App
	}
})